package threadDemo11;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyThread extends Thread{
    static int ticket=0;

    static Lock lock=new ReentrantLock();

    @Override
    public void run() {
        while (true){
            try {
                lock.lock();
                if (ticket==100){
                    break;
                }else {
                    sleep(10);
                    ticket++;
                    System.out.println(getName()+"卖的第"+ticket+"张票");
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }

        }
    }
}
